<?php
namespace app\dynamic\model;
use app\BaseModel;
use app\shop\model\AdminShopSpePrice;
use think\facade\Db;

class CardGoods extends BaseModel
{
    protected $name = 'longbing_card_goods';
    protected $append = [
        'price_text',
        'original_price'
    ];
    public function getlist($where,$limit=0){
        $data = $this->where($where)->field('id,name,cover,price,status,unit,recommend')->order('top','desc')->limit($limit)->select()->toArray();
        $data = transImagesOne($data,['cover']);
        return $data;
    }
    /**
     * User: chenniang
     * Date: 2019-09-23 15:24
     * @return void
     * descption:获取规格的第一个价格
     */
    public function getPriceTextAttr($value,$data){
        $spe_price = new AdminShopSpePrice();
        $price =  $spe_price->where(['status'=>1,'goods_id'=>$data['id']])->min('price');

        return $price;

    }

    /**
     * User: chenniang
     * Date: 2019-11-05 10:48
     * @return void
     * descption:获取规格的最低原价
     */
    public function getOriginalPriceAttr($value,$data){
        $o_dis[] = ['status','=',1];
        $o_dis[] = ['goods_id','=',$data['id']];
        $o_dis[] = ['original_price','<>',0];
        $original_price = Db::name('longbing_card_shop_spe_price')->where($o_dis)->min('original_price');
        return $original_price;
    }
}